//
//  SE_Select_View.m
//  SkyEye
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 SE. All rights reserved.
//

//精选页面

#import "SE_Select_View.h"
#import "SE_Select_TableViewCell.h"
#import "SE_Header_TableViewCell.h"
#import "SE_Item_Model.h"
#import "SE_Header_Model.h"
#import "SE_Item_VC.h"

@interface SE_Select_View()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation SE_Select_View

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableView];
    }
    return self;
}

-(void)createTableView{
    self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    [self addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[SE_Select_TableViewCell class] forCellReuseIdentifier:@"selectCell"];
    [self.tableView registerClass:[SE_Header_TableViewCell class] forCellReuseIdentifier:@"headerCell"];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.headerArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    SE_Header_Model *model = self.headerArray[section];
    
    return model.itemModelArray.count + 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        SE_Header_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"headerCell"];
        
        cell.headerModel = self.headerArray[indexPath.section];
        return cell;
    } else {
        SE_Select_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"selectCell"];
        
        SE_Header_Model *model = self.headerArray[indexPath.section];
        
        cell.itemModel = model.itemModelArray[indexPath.row - 1];
        
        return cell;

    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 0;
        } else {
            return 300;
        }
    } else {
        if (indexPath.row == 0) {
            return 60;
        } else {
            return 300;
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SE_Item_VC *VC = [[SE_Item_VC alloc]init];
//    [[self naviController]pushViewController:VC animated:YES];
    
    SE_Header_Model *model = self.headerArray[indexPath.section];
    
    VC.itemModel = model.itemModelArray[indexPath.row - 1];
    
    
    
    
    [[self naviController]presentViewController:VC animated:YES completion:nil];
}

-(void)setHeaderArray:(NSMutableArray *)headerArray{
    _headerArray = headerArray;
    [self.tableView reloadData];
}


  


@end


























